using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace OraHRDAO
{
	[Serializable]
	///<summary>
	/// DAO Class for the EMPLOYEES table.
	///</summary>
	public class EMPLOYEES : Entity
	{
		private Int32 _EMPLOYEE_ID;
		private String _FIRST_NAME;
		private String _LAST_NAME;
		private String _EMAIL;
		private String _PHONE_NUMBER;
		private DateTime _HIRE_DATE;
		private String _JOB_ID;
		private Double _SALARY;
		private Single _COMMISSION_PCT;
		private Int32 _MANAGER_ID;
		private Int32 _DEPARTMENT_ID;
	
		///Default constructor
		public EMPLOYEES ()
		{
		
		}

        /// <summary>
        /// Constructor for joins. 
		/// Available CHILD tables to join with:
		///    - DEPARTMENTS ( DEPARTMENTS_DEPT_MGR_FK )
		///    - EMPLOYEES ( EMPLOYEES_EMP_MANAGER_FK )
		///    - JOB_HISTORY ( JOB_HISTORY_JHIST_EMP_FK )
		/// Available PARENT tables to join with:
		///    - DEPARTMENTS
		///    - JOBS
		///    - EMPLOYEES
        /// </summary>
        public EMPLOYEES(bool Flat, params Entity[] entities)
            : this()
		{
			foreach(Entity entity in entities)
			{
				string[] entityParts = entity.GetType().ToString().Split('.');
				string entityName = entityParts[entityParts.Length - 1];
				PropertyInfo pf = GetType().GetProperty((entityName));
				if (pf != null)
				{
					pf.SetValue(this,new EntityCollection(entity), null);
				}
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
			}
			SetFlat(Flat);
		}

		///Constructor for Joins with flat hierarchy
        public EMPLOYEES(params Entity[] entities)
            : this(true, entities)
		{
		}
	
		///<summary>
		/// Property for column EMPLOYEE_ID.
		///</summary>
		[IsNotNullable]
		[IsPK]
		public Int32 EMPLOYEE_ID
		{
			get
			{
				return _EMPLOYEE_ID;
			}
			set
			{
				_EMPLOYEE_ID = value;
			}
		}
		///<summary>
		/// Property for column FIRST_NAME.
		///</summary>
		[MaxLength(20)]
		public String FIRST_NAME
		{
			get
			{
				return _FIRST_NAME;
			}
			set
			{
				_FIRST_NAME = value;
			}
		}
		///<summary>
		/// Property for column LAST_NAME.
		///</summary>
		[IsNotNullable]
		[MaxLength(25)]
		public String LAST_NAME
		{
			get
			{
				return _LAST_NAME;
			}
			set
			{
				_LAST_NAME = value;
			}
		}
		///<summary>
		/// Property for column EMAIL.
		///</summary>
		[IsNotNullable]
		[MaxLength(25)]
		public String EMAIL
		{
			get
			{
				return _EMAIL;
			}
			set
			{
				_EMAIL = value;
			}
		}
		///<summary>
		/// Property for column PHONE_NUMBER.
		///</summary>
		[MaxLength(20)]
		public String PHONE_NUMBER
		{
			get
			{
				return _PHONE_NUMBER;
			}
			set
			{
				_PHONE_NUMBER = value;
			}
		}
		///<summary>
		/// Property for column HIRE_DATE.
		///</summary>
		[IsNotNullable]
		public DateTime HIRE_DATE
		{
			get
			{
				return _HIRE_DATE;
			}
			set
			{
				_HIRE_DATE = value;
			}
		}
		///<summary>
		/// Property for column JOB_ID.
		///</summary>
		[IsNotNullable]
		[MaxLength(10)]
		public String JOB_ID
		{
			get
			{
				return _JOB_ID;
			}
			set
			{
				_JOB_ID = value;
			}
		}
		///<summary>
		/// Property for column SALARY.
		///</summary>
		public Double SALARY
		{
			get
			{
				return _SALARY;
			}
			set
			{
				_SALARY = value;
			}
		}
		///<summary>
		/// Property for column COMMISSION_PCT.
		///</summary>
		public Single COMMISSION_PCT
		{
			get
			{
				return _COMMISSION_PCT;
			}
			set
			{
				_COMMISSION_PCT = value;
			}
		}
		///<summary>
		/// Property for column MANAGER_ID.
		///</summary>
		public Int32 MANAGER_ID
		{
			get
			{
				return _MANAGER_ID;
			}
			set
			{
				_MANAGER_ID = value;
			}
		}
		///<summary>
		/// Property for column DEPARTMENT_ID.
		///</summary>
		public Int32 DEPARTMENT_ID
		{
			get
			{
				return _DEPARTMENT_ID;
			}
			set
			{
				_DEPARTMENT_ID = value;
			}
		}
	
	
        #region JOB_HISTORY 
        private EntityCollection _JOB_HISTORY;
		///<summary>
		/// Related table JOB_HISTORY as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(JOB_HISTORY),"JOB_HISTORY")]
        public EntityCollection JOB_HISTORY
        {
            get
            {
                return _JOB_HISTORY;
            }

            set
            {
                _JOB_HISTORY = value;
            }
        }
        private JOB_HISTORY _JOB_HISTORY_;
		///<summary>
		/// Related table JOB_HISTORY as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public JOB_HISTORY JOB_HISTORY_
        {
            get
            {
                return _JOB_HISTORY_;
            }

            set
            {
                _JOB_HISTORY_ = value;
            }
        }
        #endregion
        #region DEPARTMENTS 
        private EntityCollection _DEPARTMENTS;
		///<summary>
		/// Related table DEPARTMENTS as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(DEPARTMENTS),"DEPARTMENTS")]
        public EntityCollection DEPARTMENTS
        {
            get
            {
                return _DEPARTMENTS;
            }

            set
            {
                _DEPARTMENTS = value;
            }
        }
        private DEPARTMENTS _DEPARTMENTS_;
		///<summary>
		/// Related table DEPARTMENTS as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public DEPARTMENTS DEPARTMENTS_
        {
            get
            {
                return _DEPARTMENTS_;
            }

            set
            {
                _DEPARTMENTS_ = value;
            }
        }
        #endregion
        #region JOBS 
        private EntityCollection _JOBS;
		///<summary>
		/// Related table JOBS as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(JOBS),"JOBS")]
        public EntityCollection JOBS
        {
            get
            {
                return _JOBS;
            }

            set
            {
                _JOBS = value;
            }
        }
        private JOBS _JOBS_;
		///<summary>
		/// Related table JOBS as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public JOBS JOBS_
        {
            get
            {
                return _JOBS_;
            }

            set
            {
                _JOBS_ = value;
            }
        }
        #endregion
        #region _MANAGERS_
        private EntityCollection _MANAGERS;
		///<summary>
		/// Related table EMPLOYEES_parent as a collection for hierarchical retrieval.
		///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(MANAGERS), "MANAGERS")]
        public EntityCollection MANAGERS
        {
            get
            {
                return _MANAGERS;
            }

            set
            {
                _MANAGERS = value;
            }
        }
        private MANAGERS _MANAGERS_;
		///<summary>
		/// Related table EMPLOYEES_parent as a single object for flat retrieval.
		///</summary>
        [NotInTable]
        public MANAGERS MANAGERS_
        {
            get
            {
                return _MANAGERS_;
            }

            set
            {
                _MANAGERS_ = value;
            }
        }
        #endregion
	    /// <summary>
	    /// Gets join for current entity and table.
	    /// </summary>
	    /// <param name="tableName">Table to join with entity.</param>
	    /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
			if (string.Compare(tableName, "DEPARTMENTS", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".MANAGER_ID");
				right.Add(GetType().Name + ".EMPLOYEE_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "MANAGERS", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".MANAGER_ID");
				right.Add(GetType().Name + ".EMPLOYEE_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
			if (string.Compare(tableName, "JOB_HISTORY", StringComparison.OrdinalIgnoreCase) == 0)
			{
				ArrayList left = new ArrayList();
				ArrayList right = new ArrayList();
				left.Add(tableName + ".EMPLOYEE_ID");
				right.Add(GetType().Name + ".EMPLOYEE_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
	        if (string.Compare(tableName, "DEPARTMENTS", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".DEPARTMENT_ID");
				right.Add(GetType().Name + ".DEPARTMENT_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.LEFT_OUTER);
			}
	        if (string.Compare(tableName, "JOBS", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
				left.Add(tableName + ".JOB_ID");
				right.Add(GetType().Name + ".JOB_ID");
				return new DBJoin(left, right, JoinTypeEnumeration.INNER);
			}
			return null;
		}
	}
}


